package logic

import (
	"bw-renting/order-rpc/order"
	"context"

	"bw-renting/api/internal/svc"
	"bw-renting/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetOrderInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetOrderInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderInfoLogic {
	return &GetOrderInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// TODO: 获取订单列表
func (l *GetOrderInfoLogic) GetOrderInfo(req *types.GetOrderInfoReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.OrderServer.GetOrderInfo(context.Background(), &order.GetOrderInfoReq{
		UserId:  int64(req.UserId),
		OrderId: int64(req.OrderId),
	})
	if res.Data == "0" {
		return &types.Data{
			Code:    10001,
			Message: "列表获取失败",
			Data:    nil,
		}, nil
	}
	return &types.Data{
		Code:    200,
		Message: "列表获取成功",
		Data: map[string]string{
			"data": res.Data,
		},
	}, nil
}
